//package com.monitor.app_monitor.service.impl;
//
//import com.monitoring.exportercollect.model.Config.AppInfo;
//import com.monitoring.exportercollect.service.MonitorService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.net.ftp.FTPClient;
//import org.apache.commons.net.ftp.FTPReply;
//import org.apache.kafka.clients.consumer.KafkaConsumer;
//import org.apache.kafka.clients.producer.Producer;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
///**
// * @ClassName kafkaMonitor.java
// * @Author ning
// * @Description TODO
// * @CreateTime 2021年12月02日 16:05:00
// */
//@Service("ftpMonitor")
//@Slf4j
//public class ftpMonitor implements MonitorService {
//
//    @Qualifier("kafkaProducer")
//    @Resource
//    private Producer<String, String> kafkaProducer;
//
//    @Qualifier("kafkaConsumer")
//    @Resource
//    private KafkaConsumer<String, String> kafkaConsumer;
//
//    /**
//     * FTPClient对象
//     **/
//    private static FTPClient ftpClient = null;
//
//
//    private static final int BUFFER_SIZE = 1024 * 1024 * 4;
//
//    @Override
//    public synchronized int  receiveCode(AppInfo appInfo)  {
//        ftpClient = new FTPClient();
//        try {
//            final String[] split = appInfo.getMonitorParameter().split("-",-1);
//            String ftpAddress = split[0];
//            Integer ftpPort = Integer.valueOf(split[1]);
//            String ftpUsername = split[2];
//            String ftpPassword = split[3];
//            log.info("ftpip {},密码 {},端口 {},用户 {}",ftpAddress,ftpPassword,ftpPort,ftpUsername);
//            ftpClient.connect(ftpAddress, ftpPort);
//            ftpClient.login(ftpUsername, ftpPassword);
//            ftpClient.changeWorkingDirectory("/home/deployer/ftp/files");
//            ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
//            //限制缓冲区大小
//            ftpClient.setBufferSize(BUFFER_SIZE);
//            int reply = ftpClient.getReplyCode();
//            log.info(String.valueOf(reply));
//            if (!FTPReply.isPositiveCompletion(reply)) {
//                ftpClient.logout();
//                ftpClient.disconnect();
//                log.error(ftpAddress+"FTP服务器连接失败");
//                return 0;
//            } else {
//            }
//            log.info(String.valueOf(ftpClient.isConnected()));
//            if (!ftpClient.isConnected()){
//                ftpClient.logout();
//                ftpClient.disconnect();
//                log.error(ftpAddress+"FTP服务器连接失败");
//                return 0;
//            }
//            log.info(ftpAddress+"FTP服务器连接成功");
//            ftpClient.logout();
//            ftpClient.disconnect();
//            log.info(ftpAddress+"FTP服务器退出成功");
//            return 200;
//        } catch (Exception e) {
//            final String[] split = appInfo.getMonitorParameter().split("-",-1);
//            String ftpAddress = split[0];
//            log.error(ftpAddress+"FTP登录失败", e);
//            return 0;
//        }
//
//    }
//}
//
//
